﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using NDeployer.Engine;
using NDeployer.Studio.Common;

namespace NDeployer.Studio.Model
{
    public class TaskMetadata : ModelBase
    {
        IRunnableTask task;
        ObservableCollection<PropertyMetadata> properties;
        public TaskMetadata(IRunnableTask task)
        {
            this.task = task;
        }

        public string TaskName
        {
            get { return this.task.Name; }
        }

        public ObservableCollection<PropertyMetadata> Properties
        {
            get
            {
                if (properties == null)
                {
                    properties = new ObservableCollection<PropertyMetadata>();
                    var propertiesInfo = this.task.GetType().GetProperties();
                    foreach (var propertyInfo in propertiesInfo)
                    {
                        properties.Add(new PropertyMetadata()
                        {
                            PropertyName = propertyInfo.Name,
                            PropertyDataType = propertyInfo.PropertyType,
                            PropertyValue = Convert.ToString(propertyInfo.GetValue(this.task, null))
                        });
                    }

                }

                return properties;
            }
        }

    }
}
